home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / e / amigae21b.lha / Amiga_E_v2.1b / Sources / Other / Draw.e < prev    next >
Text File  |  1992-09-02  |  8KB  |  310 lines

  1. /* E tiny paint */
  2. /* By EA van Breemen */
  3.  
  4. /* Redone with buttons and a area boundry by Kiernan Holland.
  5. ** Well that was fun... sorry for the lazy coding. You can
  6. ** probably tell that I am a VI freak the way I copied all my code.
  7. ** Yes, I did write it all at the keyboard (look ma no flowcharts),
  8. ** but it shows you how far you can go with only six hours of experience
  9. ** on E language. The Amazing thing is it compiles on my 3000,
  10. ** E will support the AGA chipset (meaning I could get 256 colors!!!)
  11. ** and the executables are very very small thanks to Wouter van Oortmerssen.
  12. ** All I need to implement is some sort of area fill (I need to know how
  13. ** to peek the pixel values) and maybe later I could put other goodies..
  14. ** I don't care if anyone messes with this code just as long as they
  15. ** don't try to sell the executables or the source for profit..
  16. */
  17.  
  18. CONST MAXX = 480,     /* Area Maximum X Axis */
  19.       MINX = 160,     /* Area Minimum X Axis */
  20.       MAXY = 150,     /* Area Maximum Y Axis */
  21.       MINY = 50,        /* Area Minimum Y Axis */
  22.     LINEBNDX = 30,    /* Location of LINE button */
  23.     LINEBNDY = 100,
  24.     QUITBNDX = 30,    /* Location of QUIT button */
  25.     QUITBNDY = 130,
  26.     FREEBNDX = 30,    /* Location of FREE button */
  27.     FREEBNDY = 160,
  28.     WIPEBNDX = 80,    /* Location of WIPE button */
  29.     WIPEBNDY = 100,
  30.     BUTSIZ = 10,    /* Angular Symmetric (???) Button Size */
  31.     EXITCODE = 3     /* EXITCODE For Mouse Buttons (To be removed) */
  32.  
  33. PROC main()
  34.  
  35. DEF     screen,
  36.     window,
  37.     x,
  38.     y,
  39.     pendown,
  40.     stoppen,
  41.     code,
  42.     color,
  43.     lastcolor,
  44.     i,
  45.     xmax = 640,
  46.     ymax = 200,
  47.     oldfunction,
  48.     function
  49.  
  50.  
  51. screen  :=  OpenS(xmax,ymax,4,$8000,'E painting program')
  52.  
  53. IF screen=NIL THEN RETURN 10
  54.  
  55. window:=OpenW(0,0,xmax,ymax,8,$1000,'E Tiny paint ', screen,15,0)
  56.  
  57. IF window=NIL THEN RETURN CloseS(screen) AND 0+10
  58.  
  59. pendown:=FALSE
  60. stoppen:=FALSE
  61. color:=1
  62. oldfunction := 0
  63. function := 0
  64.  
  65. FOR i:=0 TO 15 STEP 1 DO Box(10+(i*15),20,i*15+20,30,i)
  66.  
  67. Box(MINX,MINY,MAXX,MAXY,2)
  68.  
  69. drawbut(LINEBNDX,LINEBNDY)
  70. resetcolor ()
  71. TextF(LINEBNDX-BUTSIZ,LINEBNDY-BUTSIZ,'LINE')
  72.  
  73. drawbut(QUITBNDX,QUITBNDY)
  74. resetcolor ()
  75. TextF(QUITBNDX-BUTSIZ,QUITBNDY-BUTSIZ,'QUIT')
  76.  
  77. drawbut(FREEBNDX,FREEBNDY)
  78. resetcolor ()
  79. TextF(FREEBNDX-BUTSIZ,FREEBNDY-BUTSIZ,'FREE')
  80.  
  81. drawbut(WIPEBNDX,WIPEBNDY)
  82. resetcolor ()
  83. TextF(WIPEBNDX-BUTSIZ,WIPEBNDY-BUTSIZ,'WIPE')
  84.  
  85. Box(10+(color*15),20,color*15+20,30,1)
  86. Box(10+(color*15)+1,21,color*15+19,29,color)
  87.  
  88. REPEAT
  89.       code:=Mouse()
  90.  
  91.       resetcolor ()
  92.     TextF(200,160,'The MOUSE is in mode \d',code)
  93.  
  94.       SELECT code
  95.         CASE 1
  96.             pendown:=TRUE
  97.             x:=MouseX(window)
  98.             y:=MouseY(window)
  99.             oldfunction := function
  100.             function := mode(x,y)
  101.             IF (function > 0)
  102.                 wait()
  103.                 pendown := FALSE
  104.             ENDIF
  105.             IF (function = 4)
  106.                 wipe ()
  107.                 function := oldfunction
  108.             ENDIF
  109.             IF (function = 0) THEN function := oldfunction
  110.         CASE 0
  111.             pendown:=FALSE
  112.         CASE 2
  113.             lastcolor:=color
  114.             INC color
  115.             IF color>15 THEN color:=0
  116.             Box(10+(lastcolor*15),20,lastcolor*15+20,30,lastcolor)
  117.             Box(10+(color*15),20,color*15+20,30,1)
  118.             Box(10+(color*15)+1,21,color*15+19,29,color)
  119.             Delay(10)
  120.         CASE EXITCODE
  121.             stoppen:=TRUE
  122.     ENDSELECT
  123.  
  124.     IF (function <> 2)
  125.        IF (pendown=TRUE) AND (function = 1)
  126.         IF (x > MAXX) THEN x := MAXX
  127.         IF (x < MINX) THEN x := MINX
  128.         IF (y > MAXY) THEN y := MAXY
  129.         IF (y < MINY) THEN y := MINY
  130.         Plot(x,y,color)
  131.           IF ((dline (x,y,color,window)) = 10) THEN stoppen := TRUE
  132.         pendown := FALSE
  133.        ENDIF
  134.        IF (pendown=TRUE) AND (function = 3)
  135.         IF (x > MAXX) THEN x := MAXX
  136.         IF (x < MINX) THEN x := MINX
  137.         IF (y > MAXY) THEN y := MAXY
  138.         IF (y < MINY) THEN y := MINY
  139.         Plot(x,y,color)
  140.           IF ((freehand (x,y,color,window)) = 10) THEN stoppen := TRUE
  141.         pendown := FALSE
  142.        ENDIF
  143.     ENDIF
  144.  
  145. UNTIL function=2
  146.  
  147. CloseW(window)
  148. CloseS(screen)
  149.  
  150. ENDPROC
  151.  
  152. PROC wipe ()
  153.     Box(MINX,MINY,MAXX,MAXY,2)
  154.     RETURN TRUE
  155. ENDPROC
  156.  
  157.  
  158. PROC freehand (startx,starty,curcolor,curwin)
  159.  
  160. DEF movex,movey,button,oldlinex,oldliney
  161.  
  162.        oldlinex := startx
  163.        oldliney := starty
  164.        IF (oldlinex > MAXX) THEN oldlinex := MAXX
  165.        IF (oldlinex < MINX) THEN oldlinex := MINX
  166.        IF (oldliney > MAXY) THEN oldliney := MAXY
  167.        IF (oldliney < MINY) THEN oldliney := MINY
  168.  
  169.     REPEAT            /* take coordinates */
  170.          button:=Mouse()
  171.        movex:=MouseX(curwin)
  172.        movey:=MouseY(curwin)
  173.        IF (movex > MAXX) THEN movex := MAXX
  174.        IF (movex < MINX) THEN movex := MINX
  175.        IF (movey > MAXY) THEN movey := MAXY
  176.        IF (movey < MINY) THEN movey := MINY
  177.          resetcolor ()
  178.        TextF(160,180,'Coordinates (x=\d, y=\d)',movex,movey)
  179.        IF button = EXITCODE THEN RETURN FALSE  /* jump out if Exit Code */
  180.          Line(oldlinex,oldliney,movex,movey,curcolor)
  181.        oldlinex := movex
  182.        oldliney := movey
  183.     UNTIL (button = 0)
  184.       resetcolor ()
  185.       TextF(160,180,'                            ')
  186.     TextF(560,20,'Ready    ')
  187.     RETURN TRUE
  188. ENDPROC
  189.  
  190.  
  191. PROC dline (startx,starty,curcolor,curwin)
  192. DEF movex,movey,button
  193.  
  194.     REPEAT            /* Wait until mouse buttons are depressed */
  195.        button := Mouse()
  196.        IF button = EXITCODE THEN RETURN FALSE /* Jump out if Exit Code */
  197.     UNTIL (button = 0)
  198.  
  199.       resetcolor ()
  200.     TextF(560,20,'Waiting  ')
  201.     Delay(15)
  202.     TextF(560,20,'Make Line')
  203.  
  204.     REPEAT            /* take coordinates */
  205.          button:=Mouse()
  206.        movex:=MouseX(curwin)
  207.        movey:=MouseY(curwin)
  208.        IF (movex > MAXX) THEN movex := MAXX
  209.        IF (movex < MINX) THEN movex := MINX
  210.        IF (movey > MAXY) THEN movey := MAXY
  211.        IF (movey < MINY) THEN movey := MINY
  212.          resetcolor ()
  213.        TextF(160,180,'Coordinates (x=\d, y=\d)',movex,movey)
  214.        IF button = EXITCODE THEN RETURN FALSE  /* jump out if Exit Code */
  215.     UNTIL (button = 1)
  216.  
  217.  Line(startx,starty,movex,movey,curcolor)
  218.  resetcolor ()
  219.  TextF(160,180,'                            ')
  220.  
  221.     REPEAT            /* Wait until mouse buttons are depressed */
  222.        button := Mouse()
  223.        IF button = EXITCODE THEN RETURN FALSE   /* Jump Out If Exit Code */
  224.     UNTIL (button = 0)
  225.     resetcolor ()
  226.     TextF(560,20,'Waiting  ')
  227.     Delay(15)
  228.     TextF(560,20,'Ready    ')
  229.     RETURN TRUE
  230. ENDPROC
  231.  
  232.  
  233. /* Delay a while to cut mouse sensitivity */
  234. PROC wait ( )
  235.     resetcolor()
  236.     TextF(560,20,'Waiting  ')
  237.     Delay(15)
  238.     TextF(560,20,'Ready    ')
  239. ENDPROC
  240.  
  241.  
  242. /* determine which button the user has pressed */
  243. PROC mode (locx,locy)
  244.     /* could it be within the line boundry? */
  245.     IF (locx > (LINEBNDX-BUTSIZ)) AND (locx < (LINEBNDX+BUTSIZ))
  246.        IF (locy > (LINEBNDY-BUTSIZ)) AND (locy < (LINEBNDY+BUTSIZ))
  247.             /* Turn Line Button On and Off */
  248.             pressbut(LINEBNDX,LINEBNDY)
  249.         resetcolor()
  250.             TextF(LINEBNDX-BUTSIZ,LINEBNDY-BUTSIZ,'LINE')
  251.         RETURN 1
  252.          ENDIF
  253.       ENDIF
  254.  
  255.     /* could it be within the quit boundry? */
  256.     IF (locx > (QUITBNDX-BUTSIZ)) AND (locx < (QUITBNDX+BUTSIZ))
  257.        IF (locy > (QUITBNDY-BUTSIZ)) AND (locy < (QUITBNDY+BUTSIZ))
  258.             /* Turn Quit Button On and Off */
  259.             pressbut(QUITBNDX,QUITBNDY)
  260.         resetcolor()
  261.             TextF(QUITBNDX-BUTSIZ,QUITBNDY-BUTSIZ,'QUIT')
  262.         RETURN 2
  263.          ENDIF
  264.       ENDIF
  265.  
  266.     /* could it be within the free boundry? */
  267.     IF (locx > (FREEBNDX-BUTSIZ)) AND (locx < (FREEBNDX+BUTSIZ))
  268.        IF (locy > (FREEBNDY-BUTSIZ)) AND (locy < (FREEBNDY+BUTSIZ))
  269.             /* Turn Quit Button On and Off */
  270.             pressbut(FREEBNDX,FREEBNDY)
  271.         resetcolor()
  272.             TextF(FREEBNDX-BUTSIZ,FREEBNDY-BUTSIZ,'FREE')
  273.         RETURN 3
  274.          ENDIF
  275.       ENDIF
  276.  
  277.     /* could it be within the wipe boundry? */
  278.     IF (locx > (WIPEBNDX-BUTSIZ)) AND (locx < (WIPEBNDX+BUTSIZ))
  279.        IF (locy > (WIPEBNDY-BUTSIZ)) AND (locy < (WIPEBNDY+BUTSIZ))
  280.             /* Turn Quit Button On and Off */
  281.             pressbut(WIPEBNDX,WIPEBNDY)
  282.         resetcolor()
  283.             TextF(WIPEBNDX-BUTSIZ,WIPEBNDY-BUTSIZ,'WIPE')
  284.         RETURN 4
  285.          ENDIF
  286.       ENDIF
  287.  
  288.     /* it wasn't any of the above */
  289.       RETURN 0
  290. ENDPROC
  291.  
  292. /* This one simulates a button press at the given X and Y coordinates */
  293. PROC pressbut (x,y)
  294.    Box(x-BUTSIZ,y-BUTSIZ,x+BUTSIZ,y+BUTSIZ,2)
  295.    Box(x-BUTSIZ+2,y-BUTSIZ+2,x+BUTSIZ-2,y+BUTSIZ-2,1)
  296.    Delay(5)
  297.    Box(x-BUTSIZ,y-BUTSIZ,x+BUTSIZ,y+BUTSIZ,1)
  298.    Box(x-BUTSIZ+2,y-BUTSIZ+2,x+BUTSIZ-2,y+BUTSIZ-2,2)
  299. ENDPROC
  300.  
  301. /* This one draws a button in its depressed form (how depressing!) */
  302. PROC drawbut (x,y)
  303.    Box(x-BUTSIZ,y-BUTSIZ,x+BUTSIZ,y+BUTSIZ,1)
  304.    Box(x-BUTSIZ+2,y-BUTSIZ+2,x+BUTSIZ-2,y+BUTSIZ-2,2)
  305. ENDPROC
  306.  
  307. PROC resetcolor ()
  308.    Plot(0,0,1)
  309. ENDPROC
  310.